from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-12-31 14:03:45.029352
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 31, Dec, 2021
Time: 14:03:49
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6566
Nobs: 522.000 HQIC: -48.1032
Log likelihood: 6053.80 FPE: 9.64275e-22
AIC: -48.3907 Det(Omega_mle): 8.12888e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.361706 0.077006 4.697 0.000
L1.Burgenland 0.098540 0.043376 2.272 0.023
L1.Kärnten -0.114539 0.022352 -5.124 0.000
L1.Niederösterreich 0.184121 0.089976 2.046 0.041
L1.Oberösterreich 0.105660 0.089719 1.178 0.239
L1.Salzburg 0.282870 0.046691 6.058 0.000
L1.Steiermark 0.022721 0.060241 0.377 0.706
L1.Tirol 0.111260 0.048626 2.288 0.022
L1.Vorarlberg -0.079623 0.042868 -1.857 0.063
L1.Wien 0.033363 0.080948 0.412 0.680
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.023013 0.169603 0.136 0.892
L1.Burgenland -0.048014 0.095534 -0.503 0.615
L1.Kärnten 0.036228 0.049230 0.736 0.462
L1.Niederösterreich -0.208280 0.198171 -1.051 0.293
L1.Oberösterreich 0.455645 0.197603 2.306 0.021
L1.Salzburg 0.312669 0.102835 3.040 0.002
L1.Steiermark 0.109027 0.132679 0.822 0.411
L1.Tirol 0.314867 0.107097 2.940 0.003
L1.Vorarlberg 0.013341 0.094416 0.141 0.888
L1.Wien 0.001361 0.178286 0.008 0.994
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.214843 0.039267 5.471 0.000
L1.Burgenland 0.092776 0.022119 4.194 0.000
L1.Kärnten -0.005658 0.011398 -0.496 0.620
L1.Niederösterreich 0.227268 0.045882 4.953 0.000
L1.Oberösterreich 0.159990 0.045750 3.497 0.000
L1.Salzburg 0.039191 0.023809 1.646 0.100
L1.Steiermark 0.029166 0.030719 0.949 0.342
L1.Tirol 0.078959 0.024796 3.184 0.001
L1.Vorarlberg 0.054927 0.021860 2.513 0.012
L1.Wien 0.109744 0.041278 2.659 0.008
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.149315 0.039278 3.801 0.000
L1.Burgenland 0.040182 0.022125 1.816 0.069
L1.Kärnten -0.013280 0.011401 -1.165 0.244
L1.Niederösterreich 0.161160 0.045894 3.512 0.000
L1.Oberösterreich 0.334366 0.045763 7.307 0.000
L1.Salzburg 0.102764 0.023816 4.315 0.000
L1.Steiermark 0.110908 0.030727 3.609 0.000
L1.Tirol 0.090403 0.024802 3.645 0.000
L1.Vorarlberg 0.053700 0.021866 2.456 0.014
L1.Wien -0.030370 0.041289 -0.736 0.462
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.142808 0.073527 1.942 0.052
L1.Burgenland -0.036679 0.041416 -0.886 0.376
L1.Kärnten -0.037748 0.021342 -1.769 0.077
L1.Niederösterreich 0.131962 0.085912 1.536 0.125
L1.Oberösterreich 0.168902 0.085666 1.972 0.049
L1.Salzburg 0.260791 0.044582 5.850 0.000
L1.Steiermark 0.079559 0.057520 1.383 0.167
L1.Tirol 0.136029 0.046429 2.930 0.003
L1.Vorarlberg 0.101145 0.040932 2.471 0.013
L1.Wien 0.056389 0.077291 0.730 0.466
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.082385 0.058064 1.419 0.156
L1.Burgenland 0.017441 0.032706 0.533 0.594
L1.Kärnten 0.051535 0.016854 3.058 0.002
L1.Niederösterreich 0.183023 0.067844 2.698 0.007
L1.Oberösterreich 0.326442 0.067650 4.825 0.000
L1.Salzburg 0.050211 0.035206 1.426 0.154
L1.Steiermark -0.002787 0.045423 -0.061 0.951
L1.Tirol 0.126668 0.036665 3.455 0.001
L1.Vorarlberg 0.060999 0.032324 1.887 0.059
L1.Wien 0.105329 0.061037 1.726 0.084
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170225 0.070394 2.418 0.016
L1.Burgenland 0.010805 0.039652 0.273 0.785
L1.Kärnten -0.061869 0.020433 -3.028 0.002
L1.Niederösterreich -0.111267 0.082251 -1.353 0.176
L1.Oberösterreich 0.221499 0.082016 2.701 0.007
L1.Salzburg 0.042223 0.042682 0.989 0.323
L1.Steiermark 0.260653 0.055069 4.733 0.000
L1.Tirol 0.490361 0.044451 11.032 0.000
L1.Vorarlberg 0.067551 0.039188 1.724 0.085
L1.Wien -0.086637 0.073998 -1.171 0.242
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.141783 0.077953 1.819 0.069
L1.Burgenland -0.010624 0.043909 -0.242 0.809
L1.Kärnten 0.063570 0.022627 2.809 0.005
L1.Niederösterreich 0.174799 0.091083 1.919 0.055
L1.Oberösterreich -0.071828 0.090822 -0.791 0.429
L1.Salzburg 0.221277 0.047265 4.682 0.000
L1.Steiermark 0.139642 0.060982 2.290 0.022
L1.Tirol 0.053103 0.049224 1.079 0.281
L1.Vorarlberg 0.143315 0.043395 3.303 0.001
L1.Wien 0.147848 0.081944 1.804 0.071
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.458090 0.044225 10.358 0.000
L1.Burgenland -0.001498 0.024911 -0.060 0.952
L1.Kärnten -0.015548 0.012837 -1.211 0.226
L1.Niederösterreich 0.183106 0.051674 3.543 0.000
L1.Oberösterreich 0.229609 0.051526 4.456 0.000
L1.Salzburg 0.025553 0.026815 0.953 0.341
L1.Steiermark -0.009910 0.034597 -0.286 0.775
L1.Tirol 0.078204 0.027926 2.800 0.005
L1.Vorarlberg 0.051721 0.024620 2.101 0.036
L1.Wien 0.003314 0.046489 0.071 0.943
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.028989 0.090307 0.157619 0.144835 0.071517 0.079952 0.012217 0.211523
Kärnten 0.028989 1.000000 -0.030796 0.131986 0.050331 0.076633 0.453014 -0.077245 0.096607
Niederösterreich 0.090307 -0.030796 1.000000 0.295883 0.109962 0.255972 0.052096 0.145866 0.258311
Oberösterreich 0.157619 0.131986 0.295883 1.000000 0.204562 0.285303 0.158882 0.128112 0.207611
Salzburg 0.144835 0.050331 0.109962 0.204562 1.000000 0.122435 0.063193 0.108540 0.084054
Steiermark 0.071517 0.076633 0.255972 0.285303 0.122435 1.000000 0.130462 0.091700 0.010374
Tirol 0.079952 0.453014 0.052096 0.158882 0.063193 0.130462 1.000000 0.059623 0.134087
Vorarlberg 0.012217 -0.077245 0.145866 0.128112 0.108540 0.091700 0.059623 1.000000 -0.017168
Wien 0.211523 0.096607 0.258311 0.207611 0.084054 0.010374 0.134087 -0.017168 1.000000